package javaJob.exercise.primary.sort_search;

/**
 * @Author: Jason
 * @ClassName: primary33
 * @Description: 第一个错误的版本
 * @Package：javaJob.exercise.primary.sort_search
 * @Project：javaDemo
 * @name：primary33
 * @Filename：primary33
 **/

/* The isBadVersion API is defined in the parent class VersionControl.
      boolean isBadVersion(int version); */

public class primary33 {

    public static void main(String[] args) {

    }

    /**
     * 标准答案
     */

//    public int firstBadVersion(int n) {
//        int top = 1;
//        int end = n;
//        int mid = 0;
//        while (top <= end) {
//            mid = top + (end - top) / 2;
//            if (isBadVersion(mid)) end = mid - 1;
//            else top = mid + 1;
//        }
//        return end + 1;
//    }

    /**
     * 自行解题
     */

//    static int firstBadVersion(int n) {
//        public int firstBadVersion(int n) {
//            int left=1;
//            int right=n;
//            while(left!=right){
//                if(isBadVersion((right-(right-left)/2))){
//                    right=right-(right-left)/2;
//                }else{
//                    left=(right-left)/2+left;
//                }
//                if(left+1==right){
//                    if(isBadVersion(left)){
//                        return left;
//                    }
//                    if(isBadVersion(right)){
//                        return right;
//                    }
//                }
//            }
//            return left;
//        }
//    }

}
